include_javaScript(url_prefix+'editor/ckeditor/ckeditor.js');
include_javaScript(url_prefix+'editor/ckfinder/ckfinder.js');


$(function() {
    $("#tabs").tabs();
});
  
$(document).ready(function() { 
    
    hs.graphicsDir = url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/';
    hs.align = 'center';
    hs.closeText = '<img border="0" src="'+url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/close_X.png" />';
    hs.creditsText = 'this.a.title';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
    hs.cacheAjax = false;
    hs.dimmingOpacity = 0.7;
    hs.onDimmerClick = function() {
        return false;
    }
    
     
    $('#btn-submit').click(function() {  
    
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
        var emailaddressVal = $("#Email").val();
        if(emailaddressVal == '') {
            $(".error").show().text(_['error-emal-empty']);
            hasError = true;
        }
    
        else if(!emailReg.test(emailaddressVal)) {
            $(".error").show().text(_['error-emal-no-format']);
            hasError = true;
        }
    
        if(hasError == true) {
            return false;
        }
    
    });
    
    $('input:checkbox[name="delId[]"]').click(function() { 
    
        if( $(this).attr("checked")== "checked"){
        
            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
        }else{
        
            if(getValCb().length>0)
            {               
                $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
            }else{
                $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
            }
        
        
        }
    
    
    
    });
});
 
function checkAll()
{
    if(getValCb().length>0){
        
        $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);
        
        $('input:checkbox[name="all"]').removeAttr("checked");
        $('input:checkbox[name="delId[]"]').removeAttr("checked");
        
    }else{
	    
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
        $('input:checkbox[name="all"]').attr("checked","checked");
        $('input:checkbox[name="delId[]"]').attr("checked","checked");
    }
	
}
function checkOne()
{
    $('input:checkbox[name="delId[]"]').click(function() { 
    
        if( $(this).attr("checked")== "checked"){

            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);

        }else{

            if(getValCb().length>0)
            {               
                $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
            }else{
                $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
            }

        }



    });
}

function getValCb()
{
    var delId = [];
    $('input:checkbox[name="delId[]"]:checked')
    .each( function(index) { 
        delId.push($(this).val());
    });
	
    return delId;
}

function change_Status(bs_url,id,status,e) {
    var tt ='';
    if(status == 'true')
    {
        tt = _['hien-thi']; 
    }
    else
    {
        tt = _['an'];
    }
        
    if (confirm("Bạn có muốn "+tt+" module này không")) 
    {
        if(id ==0)
        {
            id = getValCb('list');
           
        }
    
        var url = bs_url+ "/ajax/change/"+status+"/"+id+"/";
   
        $.ajax({ 
            type    : "GET", 
            url     : url_base+url, 
            cache   : false,
            dataType: "html",
            success : function(DataHtml)
            { 
                $("#div_html").html(DataHtml);   
            } 
        });
    }
}
function delete_module(bs_url,id,e) {
    if (confirm("Bạn có muốn xóa module này không")) 
    {
        var url = bs_url+ "/ajax/delete/"+id+"/";
   
        $.ajax({ 
            type    : "GET", 
            url     : url_base+url, 
            cache   : false,
            dataType: "html",
            success : function(DataHtml)
            { 
                $("#div_html").html(DataHtml);   
            //$(e).attr("class", value)
            } 
        });
    }
}

function active_bv(bs_url,status,page) {
    var tt ='';
    if(status == 'true')
    {
        tt =  _['showx']; 
    }
    else
    {
        tt =  _['hidex'];
    }
           
    var id_all = getValCb();
    
    if(id_all!="")
    {
       
        if (confirm(tt)) 
        {
            
            var url = bs_url+"/ajax/change/"+status+"/"+id_all;
               
            $.ajax({ 
                type    : "GET", 
                url     : url_base+ url, 
                cache   : false,
                dataType: "html",
                success : function(DataHtml)
                { 
                    $("#div_html").html(DataHtml);                    
                    checkOne()
                } 
            });
        }
    }
}
function del_bv(bs_url,id,page,option) {
    
    var id_all = getValCb();

    if(id_all!="")
    {
        if (confirm("Bạn có muốn xóa module này không")) 
        {
            var url = bs_url+ "/ajax/delete/"+id_all+"/"+page;
            $.ajax({ 
                type    : "GET", 
                url     : url_base+url, 
                cache   : false,
                dataType: "html",
                success : function(DataHtml)
                { 
                    $("#div_html").html(DataHtml);    
                    checkOne()
                } 
            });
        }
    }   
} 

function processChecked(active)
{
    var StrID = getValCb();
    
    if(StrID!=""){
        var smsCheck = confirm(sms);
        if(smsCheck==true){
            $.ajax({ 
                type: "POST", 
                url: url_base+""+strData, 
                cache: false,
                dataType: "html",
                success: function(DataHtml){ 
                    if(DataHtml=='ok')
                    {
                        for(x in StrID)
                        {
                            if(deletex)
                            {
                                $('.tr'+StrID[x]).remove();                                
                            }
                            else{
                         
                                $('.status'+StrID[x]).text(status);
                            
                                if($('.tr'+StrID[x]).hasClass('class_'+activea) )
                                    $('.tr'+StrID[x]).removeClass('class_'+activea);
                                if($('.tr'+StrID[x]).hasClass('class_'+activeb) )
                                    $('.tr'+StrID[x]).removeClass('class_'+activeb);
                            
                                $('.tr'+StrID[x]).addClass('class_'+active);
                            }                        
                        }
                    }
                    else{
                        alert(errorNotOK);                   
                    
                    }
				 
                } 
            });
        }
	
    }else{
        alert(smsError);
	
    }
}





